package org.example.domain.user_raffle.service.engine.handler;

import org.example.domain.user_raffle.model.entity.ActivityStrategyPrizeEntity;
import org.example.domain.user_raffle.repository.IUserRaffleRepo;
import org.example.domain.user_raffle.service.engine.RaffleHandlerNode;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import static java.util.Arrays.stream;

/**
 * @author lxc18
 * @date 2025/3/29 17:54
 * @description BlackListHandler
 */
@Component
public class BlackListHandler extends RaffleHandlerNode {
    @Resource
    private IUserRaffleRepo userRaffleRepo;
    public List<Long> doHandler(Long userId, Long activityId,int usedQuota, Map<String, ActivityStrategyPrizeEntity> strategyPrizeEntities) {
        //查询黑名单
//        boolean inBlackList = userRaffleRepo.isInBlackList(activityId, userId);
        ActivityStrategyPrizeEntity blackList = strategyPrizeEntities.get("blacklist");
        if(blackList.getConfig()!=null && blackList.getConfig().contains(userId.toString())){
            String[] split = blackList.getPrizeIds().split(",");
            List<Long> prizeIds = new ArrayList<>();
            stream(split).forEach(prizeId -> prizeIds.add(Long.parseLong(prizeId)));
            return prizeIds;
        }
        return next.doHandler(userId, activityId,usedQuota,strategyPrizeEntities);
    }
}
